#ifndef STM32F1_FLASH_H_
#define STM32F1_FLASH_H_

#include <stdint.h>
#include "iodef.h"

typedef struct
{
        __IO uint32_t ACR;
        __IO uint32_t KEYR;
        __IO uint32_t OPTKEYR;
        __IO uint32_t SR;
        __IO uint32_t CR;
        __IO uint32_t AR;
        __IO uint32_t RESERVED;
        __IO uint32_t OBR;
        __IO uint32_t WRPR;
}flash_reg_t;

#define FLASH_ACR_LATENCY_MASK  _VALUE(0, 0x7)
#define FLASH_ACR_LATENCY_0     _VALUE(0, 0)
#define FLASH_ACR_LATENCY_1     _VALUE(0, 1)
#define FLASH_ACR_LATENCY_2     _VALUE(0, 2)

#define FLASH_ACR_HLFCYA_ENABLE _BIT(3)
#define FLASH_ACR_PRFTBE_ENABLE _BIT(4)
#define FLASH_ACR_PRFTBS_EANBLE _BIT(5)

#define FLASH_KEY1              0x45670123
#define FLASH_KEY2              0xCDEF89AB
#define FLASH_RDPRT_KEY         0x00A5

#define FLASH   ((flash_reg_t *)FLASH_R_BASE)

#endif /* STM32F1_FLASH_H_ */
